package com.example.quartzdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.quartzdemo.entity.TaskLog;
import com.example.quartzdemo.mapper.TaskLogMapper;
import com.example.quartzdemo.service.TaskLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
@Service
public class TaskLogServiceImpl extends ServiceImpl<TaskLogMapper, TaskLog>implements TaskLogService {

    @Override
    public Page<TaskLog> taskLogs(String taskId, Integer pageNum, Integer sizeNum, LocalDateTime startTime,LocalDateTime endTime,String status) {
        LambdaQueryWrapper<TaskLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(TaskLog::getTaskId, taskId);
        if(startTime!=null||endTime!=null){
            queryWrapper.between(TaskLog::getExecTime,startTime,endTime);
        }
        if(StringUtils.isNotBlank(status)){
            queryWrapper.eq(TaskLog::getStatus,status);
        }
        Page<TaskLog> page=baseMapper.selectPage(new Page<>(pageNum,sizeNum),queryWrapper);
        //List<TaskLog> records=page.getRecords();
        //return records;
        return page;
    }
}
